/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * panelConsulta.java
 *
 * Created on 08-nov-2011, 23:19:38
 */
package edu.uoc.tdp.pac3.client.gui.panels.consulta2;

import edu.uoc.tdp.pac3.bo.IIncidenciaBO;
import edu.uoc.tdp.pac3.client.gui.model.RequestModelComboBox;
import edu.uoc.tdp.pac3.client.gui.model.RequestNoteModel;
import edu.uoc.tdp.pac3.client.gui.panels.BaseIncidenciaPanel;
import edu.uoc.tdp.pac3.domain.Request;
import edu.uoc.tdp.pac3.domain.RequestType;
import java.rmi.RemoteException;
import java.util.List;

/**
 *
 * @author fina
 */
public class PanelConsulta2 extends BaseIncidenciaPanel {

    private RequestModelComboBox requestModelComboBox;
    
    /** Creates new form panelConsulta */
    public PanelConsulta2(IIncidenciaBO bo) {
        super(bo);
        initComponents();
        setValues();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        cmbIncidencia = new javax.swing.JComboBox();
        cmbEstat1 = new javax.swing.JComboBox();
        jScrollPane2 = new javax.swing.JScrollPane();
        jList2 = new javax.swing.JList();
        jTextField1 = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 14));
        jLabel1.setText("Consulta històric");
        jLabel1.setToolTipText("");
        jLabel1.setName("jLabel1"); // NOI18N

        cmbIncidencia.setModel(getRequestModelComboBox());
        cmbIncidencia.setName("cmbIncidencia"); // NOI18N
        cmbIncidencia.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbIncidenciaActionPerformed(evt);
            }
        });

        cmbEstat1.setName("cmbEstat1"); // NOI18N
        cmbEstat1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbEstat1ActionPerformed(evt);
            }
        });

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        jList2.setEnabled(false);
        jList2.setName("jList2"); // NOI18N
        jScrollPane2.setViewportView(jList2);

        jTextField1.setEnabled(false);
        jTextField1.setName("jTextField1"); // NOI18N

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 14));
        jLabel2.setText("Descripcio");
        jLabel2.setToolTipText("");
        jLabel2.setName("jLabel2"); // NOI18N

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 14));
        jLabel3.setText("Notes:");
        jLabel3.setToolTipText("");
        jLabel3.setName("jLabel3"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addContainerGap(712, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(404, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(cmbIncidencia, javax.swing.GroupLayout.Alignment.TRAILING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(cmbEstat1, javax.swing.GroupLayout.Alignment.TRAILING, 0, 226, Short.MAX_VALUE))
                .addGap(203, 203, 203))
            .addGroup(layout.createSequentialGroup()
                .addGap(134, 134, 134)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addContainerGap())
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jLabel2)
                            .addContainerGap())
                        .addGroup(layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jTextField1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 539, Short.MAX_VALUE)
                                .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 539, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addContainerGap(160, Short.MAX_VALUE)))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(cmbEstat1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(cmbIncidencia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(44, 44, 44)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jLabel3)
                .addGap(13, 13, 13)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(88, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

private void cmbIncidenciaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbIncidenciaActionPerformed
    if(cmbIncidencia.getSelectedItem() != null){
        Request selectedRequest =(Request) cmbIncidencia.getSelectedItem();
        jTextField1.setText(selectedRequest.getDescription());

        jList2.setModel(getRequestNoteModel(selectedRequest));
    }
}//GEN-LAST:event_cmbIncidenciaActionPerformed

private void cmbEstat1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbEstat1ActionPerformed

    List<Request> request = null;    
    try {
    if(RequestType.NOTSOLVED.equals((RequestType)cmbEstat1.getSelectedItem())){
        request = getIncidenciaBO().getIncidenciesActives();
    } else {
        request = getIncidenciaBO().getIncidenciesResoltes();    
    }    
    } catch (RemoteException e) {
    } 
    requestModelComboBox = getRequestModelComboBox(request);
    cmbIncidencia.setModel(requestModelComboBox);

}//GEN-LAST:event_cmbEstat1ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox cmbEstat1;
    private javax.swing.JComboBox cmbIncidencia;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JList jList2;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextField jTextField1;
    // End of variables declaration//GEN-END:variables


    private void setValues(){
        for(RequestType rt : RequestType.values()){
            cmbEstat1.addItem(rt);
        }
    }

    @Override
    protected void setLabels() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

}
